---
title: Node adapter
sidebar:
  order: 2
---

import NodeAdapterSnippet from '../../_assets/code/reference/platform-adapters/node-adapter/adapter.ts?snippet'
import NodeResetPersistenceSnippet from '../../_assets/code/reference/platform-adapters/node-adapter/reset-persistence.ts?snippet'
import NodeWorkerMainSnippet from '../../_assets/code/reference/platform-adapters/node-adapter/worker-main.ts?snippet'
import NodeWorkerWorkerSnippet from '../../_assets/code/reference/platform-adapters/node-adapter/worker-worker.ts?snippet'
import NodeWorkerLoggingSnippet from '../../_assets/code/reference/platform-adapters/node-adapter/worker-logging.ts?snippet'

Works with Node.js, Bun and Deno.

## Example

<NodeAdapterSnippet />

## Resetting local persistence

During development you can instruct the adapter to wipe the locally persisted state and eventlog databases on startup:

<NodeResetPersistenceSnippet />

:::caution
This will delete all local data for the given `storeId` and `clientId`. It only clears local persistence and does not reset any connected sync backend. Only enable it for debugging scenarios.
:::

### Worker adapter

The worker adapter can be used for more advanced scenarios where it's preferable to reduce the load of the main thread and run persistence/syncing in a worker thread.

<NodeWorkerMainSnippet />

<NodeWorkerWorkerSnippet />

#### Logging

You can control what the Node worker logs and how it's formatted.
Pass two optional options to `makeWorker`:

- `logger` — where/format of logs (e.g. pretty console output)
- `logLevel` — how verbose logs are (`LogLevel.None` silences logs)

<NodeWorkerLoggingSnippet />

Tips:
- Use `LogLevel.None` to keep test output quiet.
- Keep the default (Debug) when diagnosing issues.
